const app = getApp()
export default {
  props: {
  },
  data: function () {
    return {
      title: 'picker-view',
      value: [],
      list: [],
      visible: true,
      indicatorStyle: `height: 34px;`
    }
  },
  watch: {
  },
  methods: {
    togglePopup(isShow, payload) {
      if (isShow) {
        const { arr, value = '' } = payload;
        this.list = arr || []
        const idx = this.list.findIndex(i => i.val == value);
        this.value = [idx == -1 ? 0 : idx];
      }
      this.$refs.basicPopup.togglePopup(isShow)
    },
    handleConfirm() {
      const val = this.list.find((item, idx) => idx == this.value[0])
      this.$emit('onConfirm', val)
      this.togglePopup(false);
    },
    handleCancel() {
      this.togglePopup(false);
    },
    bindChange(e) {
      const val = e.detail.value;
      this.value = val;
    }
  }
}